<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-lx-cascades"></i> 部门评选
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		
		<div class="container">
		
		<el-col :span="8">
			<div class="block">
			  <span class="demonstration">选择部门：</span>
			  <el-cascader
				ref="myCascader"
				v-model="value"
				:options="options"
				@change="handleChange"></el-cascader>
			</div>
		</el-col>
		<el-col :span="8">
		<el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
		
		</el-col :span="8">	
			<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header"
			 @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center"></el-table-column>
				<!-- <el-table-column label="排名"
					 width="55"
					 align="center"
				     type="index"
				     :index="indexMethod">
				   </el-table-column>-->
				<!--                <el-table-column prop="tempId" label="ID" width="55" align="center"></el-table-column>
-->
				<!--<el-table-column prop="operName" label="发布人名称"></el-table-column>-->
				<!-- <el-table-column prop="judgedId" label="排名" width="55"></el-table-column> -->
				<el-table-column prop="rank" label="排名" align="center"></el-table-column>
				<el-table-column prop="judgedName" label="部门名称" align="center"></el-table-column>
				<el-table-column prop="avgScore" label="总分" align="center"></el-table-column>
				<el-table-column label="操作" width="180" align="center">
					<template slot-scope="scope">
						<el-button type="text" icon="el-icon-upload2" @click="handleEdit(scope.$index, scope.row)">详情</el-button>

					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex" :page-size="query.pageSize"
				 :total="pageTotal" @current-change="handlePageChange"></el-pagination>
			</div>
		</div>

		<!-- 编辑弹出框 -->
		<el-dialog title="评分详情" :visible.sync="editVisible" width="80%">
			<el-table :data="edictData" border class="table" ref="multipleTable" header-cell-class-name="table-header"
						 @selection-change="handleSelectionChange">
							<el-table-column type="selection" width="55" align="center"></el-table-column>
							<!--                <el-table-column prop="tempId" label="ID" width="55" align="center"></el-table-column>
			-->
							<!--<el-table-column prop="operName" label="发布人名称"></el-table-column>-->
							<el-table-column prop="judgedName" label="评选对象" align="center"></el-table-column>
							<el-table-column prop="departmentName" label="部门" align="center"></el-table-column>
							<el-table-column prop="totalScore" label="打分" align="center"></el-table-column>
							<el-table-column prop="judgeName" label="打分人" ></el-table-column>
							
						</el-table>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: 'basetable',
		data() {
			return {
				query: {
					address: '',
					name: '',
					pageIndex: 1,
					pageSize: 10
				},
				edictData: [],
				tableData: [],
				multipleSelection: [],
				delList: [],
				editVisible: false,
				pageTotal: 0,
				form: {},
				idx: -1,
				id: -1,
				value: [],
				options: [{
				  value: '0',
				  label: '宣传部'
				  },
				  {
				  value: '1',
				  label: '组织部'
				  },
				  {
				  value: '2',
				  label: '外联部'
				  },
				  {
				   value: '3',
				   label: '秘书处'
				  },
				  {
				    value: '4',
				    label: '志愿站'
				   },
				   {
				     value: '5',
				     label: '办公室'
				    },
					{
					  value: '6',
					  label: '文体部'
					 },
					 {
					  value: '7',
					  label: '学习部'
					 },
					 {
					  value: '8',
					  label: '师友电脑维修部'
					 },
					 {
					  value: '9',
					  label: '自律部'
					 },
					 {
					  value: '10',
					  label: '网络技术部'
					 },
					 {
					  value: '11',
					  label: '辩论队'
				 }]
			};
		},
		created() {
			this.getData();
		},
		methods: {
			
			 indexMethod(index) {
			        return index+1;
			      },
			// 获取 easy-mock 的模拟数据
			async getData() {
				
				let res = await this.$Http.listTop({
						markItem: '1',
						pageNum: this.query.pageIndex,
						pageSize: this.query.pageSize
						
					},
					true
				);
				console.log(res.data);
				this.tableData = res.data.list;
				this.pageTotal = res.pageTotal || 10;
			},


			// 触发搜索按钮
			async handleSearch() {
				console.log("departmentName:"+this.$refs.myCascader.getCheckedNodes()[0].pathLabels[0]);
				let res = await this.$Http.listTop({
						markItem: '1',
						pageNum: this.query.pageIndex,
						pageSize: this.query.pageSize,
						departmentName : this.$refs.myCascader.getCheckedNodes()[0].pathLabels[0]
					},
					true
				);
				console.log(res);
				console.log(res.data);
				this.tableData = res.data.list;
				this.pageTotal = res.pageTotal || 10;
			},
			
			// 编辑操作
			async handleEdit(index, row) {
				console.log("11111111");
				console.log(this.indexMethod);
				console.log(this.tableData[1]);
				let res = await this.$Http.show_details({
						markItem: '1',
						pageNum: this.query.pageIndex,
						pageSize: this.query.pageSize,
						judgedId: this.tableData[index].judgedId
					},
					true
				);
				console.log(res);
				console.log(res.data);
				this.edictData = res.data.list;
				this.pageTotal = res.pageTotal || 10;
				this.idx = index;
				this.form = row;
				this.editVisible = true;
			},
			
		}
	};
</script>

<style scoped>
	.handle-box {
		margin-bottom: 20px;
	}

	.handle-select {
		width: 120px;
	}

	.handle-input {
		width: 300px;
		display: inline-block;
	}

	.table {
		width: 100%;
		font-size: 14px;
	}

	.red {
		color: #ff0000;
	}

	.mr10 {
		margin-right: 10px;
	}

	.table-td-thumb {
		display: block;
		margin: auto;
		width: 40px;
		height: 40px;
	}
</style>
